/*
 * @Author: jiangjin
 * @Date: 2021-10-13 14:45:40
 * @LastEditTime: 2021-10-13 15:33:47
 * @LastEditors: jiangjin
 * @Description:
 *
 */

import { InjectionKey } from 'vue'
import { createStore, Store, useStore as baseUseStore } from 'vuex'
import application from './application'
import user, { UserState } from './user'

export interface ModuleState {
  application: typeof application.state
  user: UserState
}

const store: Store<ModuleState> = createStore<ModuleState>({
  modules: {
    application,
    user,
  },
})

// 定义 injection key
export const key: InjectionKey<Store<ModuleState>> = Symbol()

// 定义自己的 `useStore` 组合式函数
export function useStore() {
  return baseUseStore(key)
}

export default store
